package com.jzoffer2;

import java.util.HashMap;
import java.util.Map;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No30
 * @description
 * @date 2021/2/4 下午2:06
 */
public class No30 {
    public static void main(String[] args) {
        String s = "abaccdeff";
        char res = firstUniqChar(s);
        System.out.println(res);
    }

    public static char firstUniqChar(String s) {
        if(s == null || s.length() == 0){
            return ' ';
        }
        Map<Character,Boolean> isFirst = new HashMap<>();
        char[] str = s.toCharArray();
        for (char c:str){
            isFirst.put(c,!isFirst.containsKey(c));
        }
        for (char c:str){
            if(isFirst.get(c)){
                return c;
            }
        }
        return ' ';
    }

}
